<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="场次名称" prop="roundName">
        <el-input
          v-model="queryParams.roundName"
          placeholder="请输入场次名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <!-- <el-form-item label="商品id" prop="goodId">
        <el-input
          v-model="queryParams.goodId"
          placeholder="请输入商品id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="每天上涨费率" prop="dayIncreaseRate">
        <el-input
          v-model="queryParams.dayIncreaseRate"
          placeholder="请输入每天上涨费率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
<!-- 
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select> 
      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ax:axRound:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ax:axRound:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ax:axRound:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ax:axRound:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="axRoundList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="id" /> -->
      <el-table-column label="名称" align="center" prop="roundName" />
      <!-- <el-table-column label="开始年月日" align="center" prop="beginYmd" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginYmd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
       <el-table-column label="销售时间" align="center" prop="dayBeginTime" width="200">
          <template slot-scope="scope">
          <span>{{scope.row.dayBeginTime }}</span>  - <span>{{scope.row.dayEndTime }}</span>
          </template>
      </el-table-column>
      <!-- <el-table-column label="销售结束时间" align="center" prop="dayEndTime" width="120"> 
      </el-table-column>  -->
      <!-- <el-table-column label="结束年月日" align="center" prop="endYmd" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endYmd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="商品" align="center" prop="axGood.goodName" /> -->
      <el-table-column label="出售时间" align="center" prop="authorizationSellTime" width="200" >
          <template slot-scope="scope">
          <span>{{scope.row.authorizationSellTime }}</span>  - <span>{{scope.row.authorizationSellTimeEnd }}</span>
          </template>
      </el-table-column>

      <!-- <el-table-column label="出售结束时间" align="center" prop="authorizationSellTimeEnd" /> -->
       <el-table-column label="排序字段" align="center" prop="orderNumber" />
      <!-- <el-table-column label="上涨费率" align="center" prop="dayIncreaseRate" >

        <template slot-scope="scope">
          <span>{{ scope.row.dayIncreaseRate}}%</span>
        </template>
      </el-table-column>


      <el-table-column label="委拍时间" align="center" prop="authorizationSellTime" /> -->

      <!-- <el-table-column label="今天价格" align="center" prop="todayPrice" />
      <el-table-column label="昨天价格" align="center" prop="yesterdayPrice" />
      <el-table-column label="前天价格" align="center" prop="beforeYesterdayPrice" />
      <el-table-column label="上限价格" align="center" prop="topPrice" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="商品库存" align="center" prop="todayGoodCount" />
      <el-table-column label="今日已售库存" align="center" prop="todaySellGoodCount" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ax:axRound:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ax:axRound:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改场次管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="场次名称" prop="roundName">
          <el-input v-model="form.roundName" style="width:200px"  placeholder="请输入场次名称" />
        </el-form-item>
        <!-- <el-form-item label="场次开始年月日" prop="beginYmd">
          <el-date-picker clearable
            v-model="form.beginYmd"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择场次开始年月日">
          </el-date-picker>
        </el-form-item> -->
         <el-form-item  label="销售开始时间" prop="dayBeginTime">
            <el-time-picker clearable
          v-model="form.dayBeginTime"
          type="time"
          placeholder="请选择销售开始时间"
          format="HH:mm:00"
          value-format="HH:mm:00"
        >
        </el-time-picker> 
          <!-- <el-input  style="width:200px"   v-model="form.dayBeginTime" placeholder="请选择销售开始时间;" /> -->
        </el-form-item>
        <el-form-item label="销售结束时间" prop="dayEndTime"> 
               <el-time-picker clearable
          v-model="form.dayEndTime"
          type="time"
          placeholder="请选择销售结束时间"
          format="HH:mm:00"
          value-format="HH:mm:00"
        >
        </el-time-picker> 
        <!-- <el-input  style="width:200px"  v-model="form.dayEndTime" placeholder="请选择销售结束时间;" /> -->
        </el-form-item> 

      <el-form-item label="出售开始时间" prop="authorizationSellTime">
         <el-time-picker clearable
          v-model="form.authorizationSellTime"
          type="time"
          placeholder="请选择出售开始时间"
          format="HH:mm:00"
          value-format="HH:mm:00"
        >
        </el-time-picker> 
        <!-- <el-input  style="width:200px"  v-model="form.authorizationSellTime" placeholder="请选择出售开始时间;" /> -->
      </el-form-item>
      <el-form-item label="出售结束时间" prop="authorizationSellTimeEnd">
        <el-time-picker clearable
          v-model="form.authorizationSellTimeEnd"
          type="time"
          placeholder="选择出售结束时间"
          format="HH:mm:00"
          value-format="HH:mm:00"
        >
        </el-time-picker> 
        <!-- <el-input  style="width:200px"  v-model="form.authorizationSellTimeEnd" placeholder="请选择出售结束时间;" /> -->
      </el-form-item>

       <el-form-item label="排序字段" prop="orderNumber">
          <el-input style="width:200px"  type="number" v-model="form.orderNumber" placeholder="请输入排序字段" />
        </el-form-item>

        <!-- <el-form-item label="场次结束年月日" prop="endYmd">
          <el-date-picker clearable
            v-model="form.endYmd"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择场次结束年月日">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="商品" prop="goodId"> 
          <el-select v-model="form.goodId" >
            <el-option
              v-for="item in axGoodList"
              :key="item.id"
              :label="item.goodName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="每天上涨费率" prop="dayIncreaseRate">
          <el-input   style="width:400px" v-model="form.dayIncreaseRate" placeholder="请输入每天上涨费率" /><span>&nbsp;%</span>
        </el-form-item>
        <el-form-item  label="今天价格" prop="todayPrice">
          <el-input style="width:400px" type="number" v-model="form.todayPrice" placeholder="请输入今天价格" />
        </el-form-item> -->
        <!-- <el-form-item label="昨天价格" prop="yesterdayPrice">
          <el-input style="width:400px" type="number"  v-model="form.yesterdayPrice" placeholder="请输入昨天价格" />
        </el-form-item>
        <el-form-item label="前天价格" prop="beforeYesterdayPrice">
          <el-input type="number" style="width:400px"  v-model="form.beforeYesterdayPrice" placeholder="请输入前天价格" />
        </el-form-item> -->

        <!-- <el-form-item label="委拍时间" prop="authorizationSellTime">
          <el-input v-model="form.authorizationSellTime" placeholder="请输入委拍时间" />
        </el-form-item> -->
        <!-- <el-form-item label="上限价格" prop="topPrice">
          <el-input  type="number" style="width:400px" v-model="form.topPrice" placeholder="请输入上限价格" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="商品库存" prop="todayGoodCount">
          <el-input style="width:400px" type="number" v-model="form.todayGoodCount" placeholder="请输入商品库存" />
        </el-form-item> -->
        <!-- <el-form-item label="今日已售库存" prop="todaySellGoodCount">
          <el-input style="width:400px" type="number"  v-model="form.todaySellGoodCount" placeholder="请输入今日已售库存" />
        </el-form-item> -->
        <!-- <el-form-item label="备注" prop="remark">
          <el-input style="width:400px"  type="textarea" v-model="form.remark" placeholder="请输入备注" />
        </el-form-item> -->
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAxRound, getAxRound, delAxRound, addAxRound, updateAxRound } from "@/api/ax/axRound";
import { listAxGood } from "@/api/ax/axGood";

export default {
  name: "AxRound",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 场次管理表格数据
      axRoundList: [],
      axGoodList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roundName: null,
        beginYmd: null,
        dayBeginTime: null,
        dayEndTime: null,
        endYmd: null,
        goodId: null,
        dayIncreaseRate: null,
        todayPrice: null,
        yesterdayPrice: null,
        beforeYesterdayPrice: null,
        topPrice: null,
        status: null,
        todayGoodCount: null,
        todaySellGoodCount: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getlistAxGood();
  },
  methods: {
    /** 查询场次管理列表 */
    getList() {
      this.loading = true;
      listAxRound(this.queryParams).then(response => {
        this.axRoundList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getlistAxGood(){
      listAxGood({}).then(response => {
        this.axGoodList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        roundName: null,
        beginYmd: null,
        dayBeginTime: "09:30:10",
        dayEndTime: "18:10:10",
        authorizationSellTime: "09:20:10",
        endYmd: null,
        goodId: null,
        dayIncreaseRate: null,
        todayPrice: null,
        yesterdayPrice: null,
        beforeYesterdayPrice: null,
        topPrice: null,
        status: null,
        todayGoodCount: null,
        todaySellGoodCount: null,
        updateTime: null,
        updateBy: null,
        createBy: null,
        createTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加场次管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAxRound(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改场次管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAxRound(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAxRound(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除场次管理编号为"' + ids + '"的数据项？').then(function() {
        return delAxRound(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ax/axRound/export', {
        ...this.queryParams
      }, `axRound_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
